<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('家族成员列表')" />
</head>
<body class="gray-bg">
     <div class="container-div">
        <div class="row">
            <div class="col-sm-12 search-collapse">
                <form id="formId">
                    <div class="select-list">
                        <ul>
                            <li>
                                <label>姓名：</label>
                                <input type="text" name="name"/>
                            </li>
                            <li>
                                <label>性别：</label>
                                <select name="sex">
                                    <option value="">所有</option>
                                    <option value="1">男</option>
                                    <option value="0">女</option>
                                </select>
                            </li>
                            <li>
                                <label>关系：</label>
                                <select name="relation">
                                    <option value="">所有</option>
                                    <option value="SELF">自己</option>
                                    <option value="FATHER">父亲</option>
                                    <option value="MOTHER">母亲</option>
                                    <option value="BROTHER">兄弟</option>
                                    <option value="SISTER">姐妹</option>
                                    <option value="SON">儿子</option>
                                    <option value="DAUGHTER">女儿</option>
                                    <option value="GRANDMA">（外）祖母</option>
                                    <option value="GRANDPA">（外）祖父</option>
                                </select>
                            </li>
                            <li>
                                <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i class="fa fa-search"></i>&nbsp;搜索</a>
                                <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i class="fa fa-refresh"></i>&nbsp;重置</a>
                            </li>
                        </ul>
                    </div>
                </form>
            </div>

            <div class="btn-group-sm" id="toolbar" role="group">
                <a class="btn btn-success" onclick="$.operate.add()" shiro:hasPermission="system:family:add">
                    <i class="fa fa-plus"></i> 添加
                </a>
            </div>
            <div class="col-sm-12 select-table table-striped">
                <table id="bootstrap-table"></table>
            </div>
        </div>
    </div>
    <th:block th:include="include :: footer" />
    <script th:inline="javascript">
        var editFlag = [[${@permission.hasPermi('system:family:edit')}]];
        var removeFlag = [[${@permission.hasPermi('system:family:remove')}]];
        var prefix = ctx + "system/family";

        $(function() {
            var options = {
                url: prefix + "/list",
                createUrl: prefix + "/add",
                updateUrl: prefix + "/edit/{id}",
                removeUrl: prefix + "/remove",
                healthUrl: prefix + "/health/{id}",
                queryHealthUrl: prefix + "/query_health/{id}",
                modalName: "家族成员",
                columns: [{
                    checkbox: true
                },
                {
                    field: 'id',
                    title: '家人信息ID',
                    visible: false
                },
                {
                    field: 'name',
                    title: '姓名'
                },
                {
                    field: 'sex',
                    title: '性别',
                    formatter: function(value, row, index) {
                        if(value == 0){
                            return '女';
                        }else if(value == 1){
                            return '男'
                        }
                    }
                },
                {
                    field: 'age',
                    title: '年龄'
                },
                {
                    field: 'relation',
                    title: '关系',
                    formatter: function(value, row, index) {
                        if(value == 'SELF'){
                            return '自己';
                        }else if(value == 'FATHER'){
                            return '父亲'
                        }else if(value == 'MOTHER'){
                            return '母亲'
                        }else if(value == 'BROTHER'){
                            return '兄弟'
                        }else if(value == 'SISTER'){
                            return '姐妹'
                        }else if(value == 'SON'){
                            return '儿子'
                        }else if(value == 'DAUGHTER'){
                            return '女儿'
                        }else if(value == 'GRANDMA'){
                            return '（外）祖母'
                        }else if(value == 'GRANDPA'){
                            return '（外）祖父'
                        }
                    }
                },
                {
                    field: 'height',
                    title: '身高'
                },
                {
                    field: 'weight',
                    title: '体重'
                },
                {
                    field: 'flag',
                    title: '状态',
                    formatter: function(value, row, index) {
                        if(value == 1){
                            return "未提交";
                        }else if(value == 2){
                            return "等待初审";
                        }else if(value == 3){
                            return "初审驳回";
                        }else if(value == 4){
                            return "等待终审";
                        }else if(value == 5){
                            return "终审驳回";
                        }else if(value == 6){
                            return "审核通过";
                        }else{
                            return "状态异常";
                        }
                    }
                },
                {
                    field: 'remark',
                    title: '备注',
                    formatter: function(value, row, index) {
                        return $.table.tooltip(value, 10, "open");
                    }
                },
                {
                    title: '操作',
                    align: 'center',
                    formatter: function(value, row, index) {
                        var actions = [];
                        if(row.flag == 1 || row.flag == 3 || row.flag == 5){
                            actions.push('<a class="btn btn-success btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="$.operate.edit(\'' + row.id + '\')"><i class="fa fa-edit"></i>编辑</a> ');
                            actions.push('<a class="btn btn-danger btn-xs ' + removeFlag + '" href="javascript:void(0)" onclick="$.operate.remove(\'' + row.id + '\')"><i class="fa fa-remove"></i>删除</a> ');
                            actions.push('<a class="btn btn-info btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="$.operate.edit_health(\'' + row.id + '\')"><i class="fa fa-edit"></i>健康信息</a> ');
                            actions.push('<a class="btn btn-primary btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="examine(\'' + row.id + '\')"><i class="fa fa-upload"></i>提交审核</a> ');
                        }else{
                            actions.push('<a class="btn btn-success disabled btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="$.operate.edit(\'' + row.id + '\')"><i class="fa fa-edit"></i>编辑</a> ');
                            actions.push('<a class="btn btn-danger disabled btn-xs ' + removeFlag + '" href="javascript:void(0)"><i class="fa fa-remove"></i>删除</a> ');
                            actions.push('<a class="btn btn-info btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="$.operate.detailHealth(\'' + row.id + '\')"><i class="fa fa-search"></i>健康信息</a> ');
                            actions.push('<a class="btn btn-primary disabled btn-xs ' + editFlag + '" href="javascript:void(0)"><i class="fa fa-upload"></i>提交审核</a> ');
                        }
                        return actions.join('');
                    }
                }]
            };
            $.table.init(options);
        });

        function examine(id){
            $.modal.confirm("确认提交审核吗?", function() {
                $.ajax({
                    cache : true,
                    type : "POST",
                    url : ctx + "system/family/submitExamine",
                    data : {
                        "familyId": id
                    },
                    async : false,
                    error : function(request) {
                        $.modal.alertError("系统错误");
                    },
                    success : function(data) {
                        $.operate.successCallback(data);
                    }
                });
            });
        }
    </script>
</body>
</html>